home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / lnklst10.zip / TESTLL.C < prev   
C/C++ Source or Header  |  1993-01-19  |  1KB  |  77 lines

  1. #include "linklist.h"
  2. #include <string.h>
  3.  
  4. char *array[] =
  5. {
  6.     "Banana",
  7.     "Apple",
  8.     "Orange",
  9.     "Grape",
  10.     "Cherry",
  11.     "Mango",
  12.     "Tomato"
  13. };
  14.  
  15. NODEPTR head, ndp;
  16.  
  17. /*---------------------------------------------------------------------------*/
  18.  
  19. void disp_ll( void )
  20. {
  21.     ndp = NodeFirst( head );
  22.  
  23.     printf( "\n" );
  24.  
  25.     for( ;; )
  26.     {
  27.         if( ndp == head )
  28.             break;
  29.         printf( "%s\n", (char *)ndp->data );
  30.         ndp = NodeNext( ndp );
  31.     }
  32.  
  33.     printf( "\nPress a key:" );
  34.     getch();
  35.     printf( "\n\n" );
  36.  
  37.     return;
  38. }
  39.  
  40. /*---------------------------------------------------------------------------*/
  41.  
  42. void main( void )
  43. {
  44.     int     i;
  45.     char    *ptr;
  46.  
  47.     head = InitList();
  48.     ndp = head;
  49.  
  50.     for( i = 0; i < 7; i++ )
  51.     {
  52.         ndp = NodeInsert( ndp, strlen( array[i] )+1 );
  53.         strcpy( (char *) ndp->data, array[i] );
  54.     }
  55.  
  56.     disp_ll();
  57.  
  58.     printf( "Deleting 3rd node..." );
  59.  
  60.     ndp = NodeNumtoPtr( 2, head );
  61.     NodeDelete( ndp );
  62.  
  63.     disp_ll();
  64.  
  65.     printf( "Inserting a 3rd node using 5th node's data..." );
  66.  
  67.     ndp = NodeNumtoPtr( 4, head );
  68.     ptr = ndp->data;
  69.  
  70.     ndp = NodeInsert( NodeNumtoPtr( 1, head ), strlen( ptr ) + 1 );
  71.     strcpy( ndp->data, ptr );
  72.  
  73.     disp_ll();
  74.  
  75. }
  76.  
  77.